package com.dp.pojo;

import java.io.Serializable;

import javax.servlet.http.HttpServletRequest;

import com.dp.pub.SysProperty;

public class JsonPage implements Serializable{
	
	private HttpServletRequest request = null;
	private String pageNo;				//当前页
	private String totalRow;			//总行数
	private String pageSize;			//每页行数
	private String totalPage;			//总页数
	private String _search;
	private String searchField;
	private String searchOper;
	private String searchString;
	private String filters;
	private String sidx="";				//指示查询排序的条件(数据库表字段或者是POJO对象的属性名)。
	private String sord="asc";			//指示查询排序的方式(asc和desc)
	
	public JsonPage(){
		
	}
	
	public JsonPage(HttpServletRequest request){
		this.request = request;
		init();
	}
	
	private  void init() {
		if (request != null) {
			pageNo = request.getParameter("jpage.pageNo");
			pageSize = request.getParameter("jpage.pageSize");
			totalRow = request.getParameter("jpage.totalRow");
			totalPage = request.getParameter("jpage.totalPage");
			_search = request.getParameter("_search");
			searchOper = request.getParameter("searchOper");
			searchString = request.getParameter("searchString");
			searchField = request.getParameter("searchField");
			filters = request.getParameter("filters");
			sidx = request.getParameter("sidx");
			sord = request.getParameter("sord");
		}
	}
	
	public String getTotalPage() {
		try{
			totalPage=String.valueOf(((int)((Integer.parseInt(getTotalRow())-1)/Integer.parseInt(getPageSize()))+1));
		}catch(Exception e){totalPage="0";}
		return totalPage;
	}
	public void setTotalPage(String totalpage) {
		this.totalPage = totalpage;
	}
	
	public String getPageNo() {
		if(pageNo==null||"0".equals(pageNo)||"".equals(pageNo)){
			pageNo = "1";
		}
		return pageNo;
	}
	public void setPageNo(String pageNo) {
		this.pageNo = pageNo;
	}
	public String getTotalRow() {
		return totalRow==null?"0":totalRow;
	}
	public void setTotalRow(String totalRow) {
		this.totalRow = totalRow;
	}
	public String getPageSize() {
		return pageSize==null?SysProperty.getPrep("rowperpage"):pageSize;
	}
	public void setPageSize(String pageSize) {
		this.pageSize = pageSize;
	}
	
	
	public String get_search() {
		return _search;
	}

	public void set_search(String _search) {
		this._search = _search;
	}

	public String getSearchField() {
		return searchField;
	}

	public void setSearchField(String searchField) {
		this.searchField = searchField;
	}

	public String getSearchOper() {
		return searchOper;
	}

	public void setSearchOper(String searchOper) {
		this.searchOper = searchOper;
	}

	public String getSearchString() {
		return searchString;
	}

	public void setSearchString(String searchString) {
		this.searchString = searchString;
	}

	public String getFilters() {
		return filters;
	}

	public void setFilters(String filters) {
		this.filters = filters;
	}

	public String getSidx() {
		return sidx;
	}
	public void setSidx(String sidx) {
		this.sidx = sidx;
	}
	public String getSord() {
		return sord;
	}
	public void setSord(String sord) {
		this.sord = sord;
	}
}
